<?php 
	require ("../connect/connect.php");
	include '../template/template_main.tpl';
	require 'epocaCtrl.php';
	
	if(isset($_SESSION["profile"]) && !($_SESSION["profile"] == "2"))
		header("Location: ../index.php");
		
	$epocas = getEpocas($conn);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../css/template.css" />
<link rel="stylesheet" type="text/css" href="../css/corpo_main.css" />
<link rel="stylesheet" type="text/css" href="../css/form.css" />
<script type="text/javascript" src="../js/jquery-1.7.2.js" ></script>
<script type="text/javascript" src="../js/main.js" ></script>

<title>.:MateMatrix:.</title>
</head>
<body>
	<?php makeHeader(); ?>
	<?php echo $estruturaInicio;?>
	<h1>- Lista de Epocas -</h1>
	<?php
		echo '<div id="forum_opcoes"><table id="forum_tabela" border=1><tr id="forum_header"><th class="lstEpocas_eNome">Nome</th><th class="lstEpocas_aNome">Autor</th><th class="forum_data">Criado</th><th class="forum_data">Alterado</th><th class="forum_data">Data Inicio</th><th class="forum_data">Data Final</th><th class="lstEpocas_editar">Editar</th></tr>';
		
		if ($epocas->num_rows > 0)
		{
			/**
			 *  $row[0] = `e`.`id`
			 *  $row[1] = `a`.`nome`
			 *  $row[2] = `e`.`data_ini`
			 *  $row[3] = `e`.`data_fim`
			 *  $row[4] = `e`.`data_criacao
			 *  $row[5] = `e`.`data_mod`
			 *  $row[6] = `e`.`nome`
			 */
			$i = 0;
			
			while ($row = $epocas->fetch_row())
			{
				$class = "";
				if (($i%2) == 1)
					$class = "forum_odd_row";
				
				printf("<tr class=\"$class\"><td class=\"lstEpocas_eNome\">%s</td><td class=\"lstEpocas_aNome\">%s</td><td class=\"forum_data\">$row[4]</td><td class=\"forum_data\">$row[5]</td><td class=\"forum_data\">$row[2]</td><td class=\"forum_data\">$row[3]</td><td class=\"lstEpocas_editar\"><form action=\"editarEpoca.php\" method=\"post\"><input type=\"hidden\" name=\"idEpoca\" value=\"$row[0]\"/><input type=\"hidden\" name=\"nomeEpoca\" value=\"%s\"/><input type=\"hidden\" name=\"dataInicio\" value=\"$row[2]\"/><input type=\"hidden\" name=\"dataFim\" value=\"$row[3]\"/><input type=\"submit\" value=\"Editar\" /></form></td></tr>", htmlspecialchars(iconv("windows-1252","utf-8",$row[6])), htmlspecialchars(iconv("windows-1252","utf-8",$row[1])), htmlspecialchars(iconv("windows-1252","utf-8",$row[6])));
				$i++;
			}
		}
		else 
			echo '<tr><td colspan="7" id="forum_semMsg">Não existem epocas registadas</td></tr>';
		echo '</table></div>';
		
		echo $estruturaFim;
	?>
	<?php echo $footer;?>
</body>
</html>